package com.cneport.das.server.trans.core;

import com.cneport.das.server.util.wmq.WebSphereMQHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * @author GavinZhang
 * @version 1.0
 * @desc： 获取Queue的名称
 * @company 东方物通科技有限（北京）公司
 * @date 2021/8/24 9:25
 */
@Component
public class QueueMetaCache {

    /**
     * websphere MQ队列管理器中已经存在的MQ。
     */
    private final static Set<String> existsQInIMBServer = Collections.synchronizedSet(new HashSet());

    @Autowired
    private WebSphereMQHelper wMQHelper;


    public boolean exists(String name) {
        return existsQInIMBServer.contains(name);
    }

    public void addExistQCache(String name) {
        existsQInIMBServer.add(name);
    }


    @PostConstruct
    public synchronized void init() {
        Set<String> names = wMQHelper.listQueueNames();
        for (String name : names) {
            existsQInIMBServer.add(name);
        }
    }

    public void loadQueues() {
        Set<String> names = wMQHelper.listQueueNames();
        for (String name : names) {
            existsQInIMBServer.add(name);
        }
    }


}
